<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.min.js"></script>
</head>
<body>
    <div id="app">
        <label>
            <input type="checkbox" name="chooseAll" v-model="chooseAll" @change="changes">全选
        </label>
        <hr>
        <label v-for="(item,index) in hobbys" :key="index">
            <input type="checkbox" name="item" v-model="choose" :value="item">{{item}}
        </label>


        {{choose}}
        {{chooseAll}}
    </div>

    <script>
        new Vue({
            el:'#app',            
            data:{
                chooseAll:false,
                choose:[],
                hobbys:[
                '乒乓',
                '游戏',
                '睡觉'
            ]
            },
            methods:{
                changes(){
                    if(this.chooseAll){
                        this.choose=this.hobbys
                    }
                    if(this.choose==this.hobbys){
                        this.chooseAll=true
                    }
                }
            }
            
        })
    </script>
</body>
</html>